# @Time : 2023/1/9
# @Author : SDAJAVA
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import time

# 创建浏览器操作对象
from selenium.webdriver.common.by import By

path = Service("chromedriver.exe")
browser = webdriver.Chrome(service=path)

url = "http://www.baidu.com"
browser.get(url)

time.sleep(2)
# 获取文本框的对象
input = browser.find_element(By.ID, 'kw')
# 给文本框输入周杰伦
input.send_keys('周杰伦')
time.sleep(2)
# 获取百度一下的按钮
button = browser.find_element(By.ID, 'su')
# 点击按钮
button.click()
time.sleep(2)
# 滑到底部
js_bottom = 'document.documentElement.scrollTop=1000000'
browser.execute_script(js_bottom)
time.sleep(2)
# 获取下一页的按钮
next = browser.find_element(By.XPATH, "//a[@class='n']")
next.click()
time.sleep(2)

# 回到上一页
browser.back()
time.sleep(2)
# 回到前一页
browser.forward()
time.sleep(2)
# 退出
browser.quit()